//
//  MappingExampleViewController.m
//  MappingExample
//

#import "MappingExampleViewController.h"

@implementation MappingExampleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
	
	map = [[MKMapView alloc] initWithFrame:[self.view bounds]];
	map.mapType = MKMapTypeSatellite;
	
	CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(37.331689,-122.03071);
	
	float zoomLevel = 0.002;
	MKCoordinateRegion region = MKCoordinateRegionMake(coords,
													   MKCoordinateSpanMake(zoomLevel, zoomLevel));
	
	[map setRegion:[map regionThatFits:region] animated:YES];
	
	[self.view addSubview:map];
	
	map.delegate = self;
	
	geo = [[MKReverseGeocoder alloc] initWithCoordinate:coords];
	geo.delegate = self;
	[geo start];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
	NSLog(@"geo error: %@", error);
	[geo cancel];
}

- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark {
	[map addAnnotation:placemark];
	[geo cancel];
}

- (void)dealloc {
	[map release];
	
	[geo cancel];
	[geo release];
	
    [super dealloc];
}

@end
